package cn.cycleif.app.service;

import cn.cycleif.app.domain.dto.ReportDTO;
import cn.cycleif.app.mapper.ReportMapper;
import cn.cycleif.entity.Report;
import cn.cycleif.enums.CommonStatusEnum;
import cn.cycleif.util.R;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Date: 25/2/11-15:22
 * @Desc:
 */
@Service
public class ReportService extends ServiceImpl<ReportMapper, Report> {

  @Autowired
  private ReportMapper reportMapper;

  public R<String> report(ReportDTO reportDTO) {
    Report report = BeanUtil.copyProperties(reportDTO, Report.class);
    if (report.getUserId() == null || report.getUserId() == 0) {
      int id = StpUtil.getLoginIdAsInt();
      report.setUserId(id);
    }
    report.setStatus(CommonStatusEnum.ACTIVE);
    reportMapper.insert(report);
    return R.success();
  }
}
